//
//  ContactDetailViewController.m
//  EWork
//
//  Created by administrator on 14-11-28.
//  Copyright (c) 2014年 gaobo. All rights reserved.
//

#import "ContactDetailViewController.h"
#import "MessageDetailViewController.h"

@interface ContactDetailViewController ()
@property int i;
@end

@implementation ContactDetailViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.editBtn.title=@"编辑";
    for(UITextField *text in self.view.subviews){
        [text setEnabled:NO];
    }
    self.contactImage.image = [UIImage imageNamed:self.contact.headImage];
    self.nameText.text = self.contact.name;
    self.departmentText.text = self.contact.department;
    self.jobText.text = self.contact.job;
    self.emailText.text = self.contact.email;
    self.mobilephoneText.text = self.contact.mobilephone;
}

- (IBAction)sendMsg:(id)sender {
    MessageDetailViewController *messageDetail = [[MessageDetailViewController alloc]init];
    [self.navigationController pushViewController:messageDetail animated:YES];
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
    //
}

- (IBAction)call:(id)sender {
    UIWebView *callWebview =[[UIWebView alloc] init];
    if(self.mobilephoneText.text == nil){
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"对方未填写手机号" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }else{
        NSURL *telURL =[NSURL URLWithString:self.mobilephoneText.text];
        [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
        [self.view addSubview:callWebview];
    }
}

- (IBAction)edit:(id)sender {
    self.i++;
    if(self.i%2==1){
        [self.editBtn setTitle:@"完成"];
        for(UITextField *text in self.view.subviews){
            [text setEnabled:YES];
        }
        self.contact.name = self.nameText.text;
        self.contact.department = self.departmentText.text;
        self.contact.job = self.jobText.text;
        self.contact.mobilephone = self.mobilephoneText.text;
        self.contact.email = self.emailText.text;
    }else{
        [self.editBtn setTitle:@"编辑"];
        for(UITextField *text in self.view.subviews){
            [text setEnabled:NO];
        }
    }
}

- (IBAction)backTap:(id)sender{
    [sender endEditing:YES];
}
@end
